<?php

class FundrecordModel extends Model
{

    public function modify($op, $str, $amount, $operID, $hash)
    {
        /**
         * $op == 1	=>	Pay/Get
         * $op == 2	=>	Financial Out/Income
         * $op == 3     =>	Investment Out/Income
         */
        if($op != 1)$operID = $_SESSION['UID'];
        $tosave = array();
        $tosave['operID'] = $operID;
        $tosave['description'] = $str;
        $tosave['__hash__'] = $hash;
        $F = D('Fund');
        $history = $F->find();
        $tosave['htotal'] = $history['total'];
        $tosave['hatotal'] = $history['atotal'];
        $tosave['hparts'] = $history['parts'];
        if ($op == 1)
        {
            $tosave['totalvalue'] = $amount;
            $tosave['value'] = $amount;
            $f = $F->find();
            $per = $f['total'] / $f['parts'];
            $tosave['parts'] = $amount / $per;
            $F->pay($tosave['parts']);
        }
        else if ($op == 2)
        {
            $tosave['totalvalue'] = $amount;
            $tosave['parts'] = 0;
            $tosave['value'] = 0;
            $F->financial($amount);
        }
        else
        {
            $tosave['totalvalue'] = $amount;
            $tosave['parts'] = 0;
            $tosave['value'] = $amount;
            $F->income($amount);
        }
        if($this->create($tosave))
        {
            $this->add();
            return "Done!";
        }
        else return $this->getError();
    }

}

?>